home *** CD-ROM | disk | FTP | other *** search
- /**-------------------------------------------------------------------------------------
- *
- *
- * MenuHook/MBarHook exposed
- * Visual proof these things do get called!
- *
- *
- * Matt Deatherage 12/07/92
- *
- *
- **-----------------------------------------------------------------------------------**/
-
- #define rMenuBar 128
- #define mApple 128
- #define mFile 129
- #define mChoices 133
- #define rAboutAlert 128
- #define iAbout 1
- #define iQuit 8
- #define rWindow 128
- #define SetMBarHook ((ProcPtr *)MBarHook) // necessary for MPW
- #define SetMenuHook ((ProcPtr *)MenuHook) // necessary for MPW
-
-
- void InitMyStuff(void);
- void DoEventLoop(void);
- void DoUpdate(WindowPtr window);
- pascal void MyMBarHook(Rect * theRect);
- pascal void MyMenuHook(void);
-
- /*------ main ----------------------------------------------------------------------------*/
-
- Rect Rect1,Rect2;
- WindowPtr myWindow;
- Boolean gQuit;
-
- main()
-
- {
-
- GrafPort myPort;
-
- InitGraf((Ptr) &thePort);
- OpenPort(&myPort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- SetRect(&Rect1,5,5,15,15);
- SetRect(&Rect2,5,20,15,30);
-
- InitMyStuff();
- DoEventLoop();
- CloseWindow(myWindow);
-
- } /* main */
-
- /*------ InitMyStuff ---------------------------------------------------------------------*/
-
- void InitMyStuff()
-
- {
-
- Handle menuBar;
- MenuHandle theMenu;
-
-
- menuBar = GetNewMBar(rMenuBar);
- if (menuBar == NULL)
- ExitToShell();
- SetMenuBar(menuBar);
- DisposHandle(menuBar);
-
- theMenu = GetMenu(mChoices);
- InsertMenu(theMenu, -1); /* stick this in the hierarchical list */
-
- AddResMenu(GetMHandle(mApple),'DRVR'); /* DA names to the Apple menu */
- DrawMenuBar();
-
- // *SetMBarHook = MyMBarHook; for MPW
- MBarHook = MyMBarHook; // for THINK C
-
- // *SetMenuHook = MyMenuHook; for MPW
- MenuHook = MyMenuHook;
-
- myWindow = GetNewWindow(rWindow, NULL, (WindowPtr)-1L);
- ShowWindow(myWindow);
- SetPort(myWindow);
-
-
-
-
- }
-
-
- /*------ DoMenuCommand -------------------------------------------------------------------*/
-
-
- void DoMenuCommand(menuResult)
- long menuResult;
-
- {
- short menuID; /*the ID of the selected menu*/
- short menuItem; /*the item number of the selected menu*/
- short itemHit;
- Str255 daName;
- short daRefNum;
-
-
- menuID = (menuResult >> 16); /*use built-ins (for efficiency)...*/
- menuItem = (menuResult & 0xFFFF); /*to get menu item number and menu number*/
- switch (menuID) {
- case mApple:
- switch (menuItem){
-
- case iAbout:
- itemHit = Alert(rAboutAlert, nil);
- break;
-
- default:
- /*all non-About items in this menu are DAs*/
- GetItem(GetMHandle(mApple),menuItem,daName);
- daRefNum = OpenDeskAcc(daName);
- break;
- }
-
- case mFile:
- switch (menuItem){
- case iQuit:
- gQuit = TRUE;
-
- default:
- break;
- }
- };
- HiliteMenu(0); /*unhighlight what MenuSelect (or MenuKey) hilited*/
- }
-
-
- /*------ DoEvent ------------------------------------------------------------------------*/
-
-
- void DoEvent(event)
-
- EventRecord * event;
-
- {
- short part, err;
- WindowPtr window;
- Point aPoint;
- char key;
-
- switch (event->what) {
- case mouseDown:
- {
- part = FindWindow(event->where, &window);
- switch (part) {
- case inMenuBar: /*process the menu command*/
- {
- DoMenuCommand(MenuSelect(event->where));
- break;
- };
- case inSysWindow: /*let the system handle the mouseDown*/
- {
- SystemClick(event, window);
- break;
- }
- case inDrag: /*pass screenBits.bounds to get all gDevices*/
- {
- DragWindow(window, event->where, &screenBits.bounds);
- break;
- }
- default:
- ;
- };
- break;
- };
- case keyDown:
- case autoKey:
- { /*check for menukey equivalents*/
- key = (event->message & charCodeMask);
- if (event->modifiers & cmdKey) /*Command key down*/
- if ( event->what == keyDown)
- {
- DoMenuCommand(MenuKey(key));
- };
- break;
- };
- case updateEvt:
- {
- DoUpdate((WindowPtr)event->message);
- break;
- }
- case diskEvt:
- {
- if ( (event->message) != noErr )
- {
- SetPt(&aPoint,50,50);
- err = DIBadMount(aPoint, event->message);
- };
- break;
- }
- default:;
- };
- }
- /*DoEvent*/
-
- /*------ DoUpdate ----------------------------------------------------------------------*/
-
- void DoUpdate(window)
- WindowPtr window;
- {
-
- Rect tempRect;
-
- SetPort(window);
- BeginUpdate(window); /*sets up the visRgn, clears updateRgn*/
- if (!EmptyRgn(window->visRgn)) /*draw if updating needs to be done*/
- {
- /* tempRect = (*(window->visRgn))->rgnBBox */
- tempRect = (*(window->visRgn))->rgnBBox;
- EraseRect(&tempRect);
- FrameRect(&Rect1);
- FrameRect(&Rect2);
- MoveTo(20,15);
- DrawString("\pMenuHook being called");
- MoveTo(20,30);
- DrawString("\pMBarHook being called");
- EndUpdate(window); /*restores the visRgn*/
- }
- }
-
- /*------ DoEventLoop -----------------------------------------------------------------------*/
-
- void DoEventLoop()
-
- {
-
- Boolean gotEvent;
- EventRecord event;
-
-
- gQuit = FALSE;
-
- do {
- /*put us 'asleep' forever under MultiFinder*/
- gotEvent = WaitNextEvent(everyEvent, &event, 0xFFFFFFFF, NULL);
-
- if ( gotEvent )
- DoEvent(&event);
- }
- while (gQuit == FALSE); /*loop forever; we quit through an ExitToShell*/
- }
-
-
- /*------ MyMBarHook -----------------------------------------------------------------------*/
-
- pascal void MyMBarHook(theRect)
-
- Rect * theRect;
-
- {
-
- GrafPtr oldPort;
- long theTicks;
-
- GetPort(&oldPort);
- SetPort(myWindow);
-
- theTicks = TickCount();
- InvertRect(&Rect2);
- while (theTicks + 10 >= TickCount());
- InvertRect(&Rect2);
-
- SetPort(oldPort);
-
-
- InvertRect(theRect);
-
-
- asm {
- moveq.l #0,D0
- };
-
- }
-
- /*------ MyMenuHook -----------------------------------------------------------------------*/
-
- pascal void MyMenuHook()
-
- {
-
- GrafPtr oldPort;
- long theTicks;
-
- GetPort(&oldPort);
- SetPort(myWindow);
-
- theTicks = TickCount();
- InvertRect(&Rect1);
- while (theTicks + 1 >= TickCount());
- InvertRect(&Rect1);
- while (theTicks + 1 >= TickCount());
-
- SetPort(oldPort);
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-